
package fhedu;

import control.KiemTraDangNhap;
import control.LayDuLieuDiem;
import javax.microedition.lcdui.*;

import javax.microedition.lcdui.game.GameCanvas;
import view.ShowAlert;
import obj.objResponseScore;
import global.Global;
import global.CurrentUserInfor;
/**
 *
 * @author kUN
 */

public class menu extends GameCanvas implements CommandListener{
    Form frmChonKyHoc;
    ChoiceGroup kyhoc;
    Command quaylai=new Command("Quay lại", Command.BACK,1);
    Command tieptuc=new Command("Tiếp tục", Command.OK,0);
    int rong=getWidth();
    int cao=getHeight();
    Image bgmenu;
    Image menu;
    int focus=0;
    CellMeNu mangmenu[]=new CellMeNu[5];
    Graphics g=getGraphics();
    Graphics gmenu;
    TextField txt1;
     int trangthai=1;
  //  Ticker ticker=new Ticker("Xin chào: Bùi Thanh Minh. Bạn có 2 cập nhật mới. Chọn menu để xem cập nhật");
//--ky hoc
    public void intChonKy()
    {
        frmChonKyHoc=new Form("Chọn Kỳ Học");
        frmChonKyHoc.setCommandListener(this);
        frmChonKyHoc.addCommand(quaylai);
        frmChonKyHoc.addCommand(tieptuc);
        kyhoc=new ChoiceGroup("Chọn kỳ", ChoiceGroup.POPUP);
        
        kyhoc.append("Kỳ 1                ", null);
        kyhoc.append("Kỳ 2", null);
        kyhoc.append("Kỳ 3", null);
        kyhoc.append("Kỳ 4", null);
        kyhoc.append("Kỳ 5", null);
        kyhoc.append("Kỳ 6", null);
        kyhoc.append("Kỳ 7", null);
        kyhoc.append("Kỳ 8", null);        
        frmChonKyHoc.append(kyhoc);
    
        
    }
//---
    menu()
    {
        super(false);
       // this.setTicker(ticker);
        this.setFullScreenMode(true);
       // gmenu.drawString(rong+"  "+ cao, 10, 10, Graphics.TOP|Graphics.LEFT);
        menu=Image.createImage(240,320);
        gmenu=menu.getGraphics();
        gmenu.setFont(MyFont.fontnhodam);
        try{
        bgmenu=Image.createImage("Image/bgmenu.png");
        gmenu.drawImage(bgmenu, 0, 0, Graphics.TOP|Graphics.LEFT);
        }catch(Exception e){};
      
       //CurrentUserInfor.nguoiDungDanngNhap.getiTrangthai()
        if(trangthai==0)
        {
            mangmenu[0]=new CellMeNu("Image/iclich.png", "Tra cứu lịch học");
            mangmenu[0].Draw(gmenu, 20, 181);
            mangmenu[1]=new CellMeNu("Image/icdiem.png", "Tra cứu điểm thi");
            mangmenu[1].Draw(gmenu, 20, 202);
            mangmenu[2]=new CellMeNu("Image/thongbao.png", "Xem thông báo");
            mangmenu[2].Draw(gmenu, 20, 223);
            mangmenu[3]=new CellMeNu("Image/icgioithieu.png", "Giới thiệu");
            mangmenu[3].Draw(gmenu, 20, 244);
            mangmenu[4]=new CellMeNu("Image/icthoat.png", "Thoát");
            mangmenu[4].Draw(gmenu, 20, 265);
            
        }else if(trangthai==1)
        {
            mangmenu[0]=new CellMeNu("Image/iclich.png", "Lịch Giảng Dạy");
            mangmenu[0].Draw(gmenu, 20, 181);
            mangmenu[1]=new CellMeNu("Image/icphanhoi.png", "Phản Hồi");
            mangmenu[1].Draw(gmenu, 20, 202);
            mangmenu[2]=new CellMeNu("Image/thongbao.png", "Thông Báo");
            mangmenu[2].Draw(gmenu, 20, 223);
            mangmenu[3]=new CellMeNu("Image/icgioithieu.png", "Giới thiệu");
            mangmenu[3].Draw(gmenu, 20, 244);
            mangmenu[4]=new CellMeNu("Image/icthoat.png", "Thoát");
            mangmenu[4].Draw(gmenu, 20, 265);
        }
        mangmenu[focus].FoCus(gmenu);
        g.drawImage(menu, 0, 0, Graphics.TOP|Graphics.LEFT);        
        flushGraphics();
        
    }
    void refresh(Graphics g)
    {
        g.drawImage(menu, 0, 0, Graphics.TOP|Graphics.LEFT);        
        flushGraphics();
    }
    public void keyPressed(int k)
    {
        switch(getGameAction(k))
        {
            case UP:
                if(focus>0)
                {
                mangmenu[focus].UnFocus(gmenu);
                mangmenu[focus-1].FoCus(gmenu);
                focus-=1;    
                this.refresh(g);
                } else if(focus==0)
                {
                    mangmenu[focus].UnFocus(gmenu);
                    focus=4;
                    mangmenu[focus].FoCus(gmenu);
                    this.refresh(g);
                }
                break;
            case DOWN:
                if(focus<4)
                {
                mangmenu[focus].UnFocus(gmenu);
                mangmenu[focus+1].FoCus(gmenu);
                focus+=1;    
                this.refresh(g);
                } else if(focus==4){
                  mangmenu[focus].UnFocus(gmenu);
                  focus=0;
                  mangmenu[focus].FoCus(gmenu);
                  this.refresh(g);
                }
                break;
            case FIRE:
                if(focus==1)
                {
                    
                    
                    bgmenu=null;
                    menu=null;    
                    g=null;
                    gmenu=null;
                    mangmenu=null;
                    if(trangthai==1){
                        intChonKy();                
                        FHEDU.display.setCurrent(frmChonKyHoc);
                    }else
                    {
                        //set form phản hồi
                    }
                }
                else if(focus==4)
                {
                    bgmenu=null;
                    menu=null;    
                    g=null;
                    gmenu=null;
                    mangmenu=null;                    
                   FHEDU.display.setCurrent(FHEDU.frmDangnhap);
                }
                
                break;
        }
        
    }

    public void commandAction(Command c, Displayable d) {
        String label=c.getLabel();
        if(label.equals("Quay lại"))
        {
            frmChonKyHoc=null;
            FHEDU.display.setCurrent(new menu());
        }else if(label.equals("Tiếp tục"))
        {
            String ky=kyhoc.getString(kyhoc.getSelectedIndex());
            if(ky.equals("Kỳ 1                "))
            {
                Global.kyhoc=1;
                                
            }else if(ky.equals("Kỳ 2"))
            {
                Global.kyhoc=2;
            }else if(ky.equals("Kỳ 3"))
            {
                Global.kyhoc=3;
            }else if(ky.equals("Kỳ 4"))
            {
                Global.kyhoc=4;
            }else if(ky.equals("Kỳ 5"))
            {
                Global.kyhoc=5;
            }else if(ky.equals("Kỳ 6"))
            {
                Global.kyhoc=6;
            }else if(ky.equals("Kỳ 7"))
            {
                Global.kyhoc=7;
            }else 
            {
                Global.kyhoc=8;
            }
            frmChonKyHoc=null;
            FHEDU.display.setCurrent(new XemDiem());
//           objResponseScore response=new objResponseScore();
//           response= LayDuLieuDiem.LayDuLieu("SV08B602", "7");           
//          
//           ShowAlert.ShowAlert(FHEDU.display, frmChonKyHoc,"", response.getObjDiems()[1].getsMon(), 1); 
            
           
        }
        
    }
    
}
